<template>
<div>
    <meta title="微信公众号管理"></meta>
    <ManageTable border stripe :rowKey="tableData.rowKey" :columns="tableData.columns" :data="tableData.data" :btnGroup="tableData.btnGroup" :page="tableData.page" @on-page-change="onPageChange">

    </ManageTable>

</div>
</template>

<script>
import then from 'thenjs';
import moment from 'moment';
import AppFrame from '../../libs/app-frame';
import ManageTable from '../../components/manage-table';

export default {
    data: function() {
        return {
            tableData: {
                rowKey: 'WX_ID',
                columns: [{
                        type: 'selection',
                        width: 60,
                        align: 'center',
                          able:'禁止删除'
                    },

                    {
                        title: '名称',
                        key: 'WX_AppName',
                        filterKey: 'WX_AppName',
                        sortable: 'custom',
                        filterType: 'text'
                    },
                    {
                        title: '类型',
                        key: 'WX_AppType',
                        width: 120
                    },

                    {
                        title: '更新时间',
                        width: 180,
                        key: 'WX_UpdateTime',
                        filterType: 'dateTime',
                        sortable: 'custom'
                    },
                  
                    {
                        title: '创建时间',
                        width: 180,
                        key: 'WX_CreateTime',
                        filterType: 'dateTime',
                        sortable: 'custom'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 80,
                        align: 'center',
                         able:'禁止编辑',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.$router.push("/Manage/Weixin/Manage/Edit?id=" + params.row.Art_ID);
                                        }
                                    }
                                }, '编辑')
                            ]);
                        }
                    }
                ],
                data: [],
                btnGroup: [{
                    key: 'delBtn',
                    text: '删除所选',
                    type: 'primary',
                    url: '/manage-api/weixin/del',
                    isShow: true,
                    icon: 'trash-a',
                    loading: false,
                    able:'禁止删除',
                    actionText: '确定要删除所选吗?'
                }],
                page: {
                    total: 0,
                    current: 1,
                    pageSize: 20
                }
            },
            QueryModel: {
                Sort: null
            }
        }
    },
    components: {
        ManageTable
    },
    created: function() {
        this.setDefaultData();
        this.find();
    },
    watch: {
        '$route': function() { //当路由改变时
            //alert( JSON.stringify(this.$route.query));
            this.setDefaultData();
            this.find();
        }

    },
    methods: {
        setDefaultData: function() {
            this.tableData.page.current = Number(this.$route.query.CurPage) || 1;
            this.tableData.page.pageSize = Number(this.$route.query.PageSize) || 20;
        },
      
        find: function(curPage, pageSize) {
            try {
                let self = this;
                let PostData = {};
                if (this.$route.query) PostData = this.$route.query;
                PostData.CurPage = this.tableData.page.current;
                PostData.PageSize = this.tableData.page.pageSize;

                AppFrame.Http.Post("/manage-api/weixin/items/getItems", PostData).then(function(ResultBody) {
                    let Ret = ResultBody.data;
                     console.log(Ret);
                    self.tableData.page.total = Ret.Data.RsCount;
                    self.tableData.page.current = Ret.Data.CurPage;
                    self.tableData.page.pageSize = Ret.Data.PageSize;
                    //console.log(Ret);
                    //----填充列的过滤属性
                    self.tableData.columns.forEach(function(col) {
                        if (col.key == 'Art_Labelname') {
                            col.filterOptions.splice(0, col.filterOptions.length);
                            col.filterOptions = Ret.Data.ArtLabels;
                            //console.log(col.filterOptions);
                        }
                    });
                    //------------------
                    self.tableData.data.splice(0, self.tableData.data.length);
                    Ret.Data.DataList.forEach(function(item) {
                        //item.UserCreatetime = moment.unix(item.UserCreatetime).format('YYYY-MM-DD hh:mm:ss');
                        self.tableData.data.push(item);
                    });

                    // console.log(Ret.Data);
                }).catch(function(err) {
                    console.log(err);
                    self.$Message.error(JSON.stringify(err));
                })
            } catch (err) {

            }

        },
         onPageChange: function(page) {
            if (page.current !== this.tableData.page.current) {

            }
        }
    }
}
</script>

<style scoped>

</style>